package com.wkbb.sports.websocket;

import lombok.Getter;

/**
 * websocket响应指令和接收指令是成对响应的，成功才响应，失败直接断开
 */
@Getter
public enum WebsocketEnum {

    VERIFY_TOKEN(10001, "验证token"),
    VERIFY_TOKEN_RESPONSE(20001, "验证token响应"),
    VERIFY_TOKEN_ERROR_RESPONSE(30001, "token非法响应"),

    ACCEPT_JUMP_ROPE_NUM(10002, "接收跳绳数量"),
    ACCEPT_JUMP_ROPE_NUM_RESPONSE(20002, "接收跳绳数量响应"),
    ACCEPT_JUMP_ROPE_NUM_ERROR_RESPONSE(30002, "接收跳绳数量参数为空非法"),

    HEARTBEAT(10003, "心跳检测"),
    HEARTBEAT_RESPONSE(20003, "心跳检测响应"),

    RANK(10004, "排名"),
    RANK_RESPONSE(20004, "排名响应"),
    RANK_ERROR_RESPONSE(30004, "排名参数为空非法"),

    ACCEPT_JUMP_ROPE_NUM_THIRD(10005, "实时返回前三名或者含自己的四名给前端的跳绳数量"),
    ACCEPT_JUMP_ROPE_NUM_THIRD_RESPONSE(20005, "实时返回前三名或者含自己的四名给前端的跳绳数量响应"),

    ERROR_RESPONSE(99999, "指令不存在"),
    ERROR_DATA_RESPONSE(99998, "数据格式异常"),
    CONNECT_SUCCESS(99997, "连接成功"),
    RESET(99996, "重置成功"),
    ;

    private Integer code;
    private String desc;

    WebsocketEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * @author: lbh
     * @date: 2018-10-15 16:26
     * @deprecation: 通过code返回枚举
     */
    public static WebsocketEnum parse(int code) {
        WebsocketEnum[] values = values();
        for (WebsocketEnum value : values) {
            if (value.getCode() == code) {
                return value;
            }
        }
        throw new RuntimeException("Unknown code of WebsocketEnum");
    }


}
